package logic

import (
	"common/comCopier"
	"common/dao/model"
	"common/mysql"
	"context"

	"gateway/internal/svc"
	"gateway/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DatauserInfoListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDatauserInfoListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DatauserInfoListLogic {
	return &DatauserInfoListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DatauserInfoListLogic) DatauserInfoList(req *types.ListRequest) (resp *types.ListData, err error) {
	// todo: add your logic here and delete this line
	params := mysql.QueryList{
		Page:    int(req.Page),
		Size:    int(req.PageSize),
		Key:     "name",
		FindKey: req.Keyword,
		DB:      l.svcCtx.DB,
	}
	list, count, err := mysql.GETList[model.Room](&params)
	if err != nil {
		return nil, err
	}
	err = comCopier.CopyWithOption(&resp.List, list)
	if err != nil {
		return nil, err
	}
	resp.Total = count
	return resp, nil
}
